import { Component, Inject } from '@angular/core';
import { IonicPage, App, ModalController, NavController } from 'ionic-angular';

// util service
import { AlertService } from '../../../../providers/utils/alert.service';

/**
 * 根据原密码直接重置密码
 */
@IonicPage()
@Component({
  selector: 'page-reset-password',
  templateUrl: 'reset-password.html'
})
export class ResetPasswordPage {

  // 充值
  reset_password: any= {
    old_password: '',
    new_password: '',
    req_password: ''
  };

  // 是否显示密码
  switchover_password: any = {
    type: 'password',
    status: true
  };

  constructor(
    private navCtrl: NavController,
    private appCtrl: App,
    private modalCtrl: ModalController,
    private alertCtrl: AlertService,
    @Inject('auth') private authService,
  )
  {}

  /*** 切换密码显示方式
  * */
  public switchoverPassword(obj: any): void
  {
    if(!obj.type) return;
    this.switchover_password = {
      type: obj.type==='text'? 'password': 'text',
      status: !obj.status
    }

  }

  /*** 执行登录操作
  * */
  public executeUpdatePassword(): void
  {
    if(this.reset_password.new_password !== this.reset_password.req_password)
    {
      this.alertCtrl.createAgreeAlert('两次输入不一致');
      return;
    }
    this.authService.updatePwdByOldPwd(this.reset_password,this.appCtrl, this.modalCtrl);
  }

  /***
   * 打开忘记密码
   * */
  public doForget(): void
  {
    this.navCtrl.push('ForgetPage');
  }

}
